package com.foryou.wechat.controller;

import com.foryou.wechat.common.Constants;
import com.foryou.wechat.service.HotWordService;
import com.foryou.wechat.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/v/hot")
public class HotController {

    @Autowired
    private HotWordService hotWordService;

    @GetMapping("/addHotWord")
    public Response addHotWord(String hotWord) {
        try {
            hotWordService.addHotWord(hotWord);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Response.success();
    }

    @GetMapping("/getHotWordList")
    public Response getHotWordList(int topN) {
        try {
            return Response.success(hotWordService.getHotWord(topN));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Response.failure(Constants.OPERATION_FAILURE);
    }
}
